home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 031a / wedl120.zip / DEMO3.C < prev    next >
C/C++ Source or Header  |  1991-12-09  |  6KB  |  145 lines

  1.  
  2. /*---------------------------------------------------------------------------*/
  3. /*                                                                           */
  4. /*          WEDL - Windows Enhanced Dialog Library                           */
  5. /*          Copyright (c) 1991, Mike Smedley                                 */
  6. /*          All Rights Reserved                                              */
  7. /*          Module:  DEMO3.C                                                 */
  8. /*                                                                           */
  9. /*---------------------------------------------------------------------------*/
  10.  
  11. #include <windows.h>
  12. #include <stdio.h>
  13. #include "wedl.h"
  14. #include "demo.h"
  15. #include "demohelp.h"
  16.  
  17. /*---------------------------------------------------------------------------*/
  18.  
  19. static void fill_list_boxes( HWND hDlg, PSTR pathspec );
  20.  
  21. /*---------------------------------------------------------------------------*/
  22.  
  23. static PSTR protocols[] = { "Xmodem", "Ymodem", "Zmodem" };
  24.  
  25. /*---------------------------------------------------------------------------*/
  26.  
  27. int FAR PASCAL DialogProc3( HWND hDlg, unsigned message, WORD wParam,
  28.                             LONG lParam )
  29. {
  30.     static HFORM hform = NULL;
  31.     static int protocol = 0, hangup;
  32.     static char path_spec[81], file_name[13];
  33.  
  34.     switch( message ) {
  35.         case WM_INITDIALOG:
  36.             hform = form_begin( hDlg );
  37.             form_set_help( hform, "demohelp.hlp" );
  38.             field_define( hform, ID_FILENAME, file_name, DT_STRING,
  39.                           "F(12)", FDF_VAFFRM | FDF_NOTBLANK,
  40.                           pcheck_file_name, BAD_FILENAME, HELPID_FILENAME );
  41.             genctrl_define( hform, ID_FILEBOX, HELPID_FILEBOX );
  42.             genctrl_define( hform, ID_DIRBOX, HELPID_DIRBOX );
  43.             button_define( hform, ID_XMODEM, &protocol, 1, 0, 0,
  44.                            BS_USEDATA, HELPID_XMODEM );
  45.             button_define( hform, ID_YMODEM, &protocol, 1, 1, 0,
  46.                            BS_USEDATA, HELPID_YMODEM );
  47.             button_define( hform, ID_ZMODEM, &protocol, 1, 2, 0,
  48.                            BS_USEDATA, HELPID_ZMODEM );
  49.             button_define( hform, ID_HANGUP, &hangup, 0, TRUE, FALSE,
  50.                            BS_OFF, HELPID_HANGUP );
  51.             form_end( hform );
  52.             fill_list_boxes( hDlg, "*.*" );
  53.             return( TRUE );
  54.  
  55.         case WM_COMMAND:
  56.             dproc_enter_wm_command( hform, wParam, lParam );
  57.             switch( wParam ) {
  58.  
  59.                 case IDOK:
  60.                     dproc_enter_idok( hform );
  61.                     if( !form_in_error_cond( hform ) ) {
  62.                         if( form_validate( hform ) != NULL ) break;
  63.                         form_process( hform );
  64.                         GetDlgItemText( hDlg, ID_PATHSPEC, path_spec, 80 );
  65.                         EndDialog( hDlg, TRUE );
  66.                         form_terminate( hform );
  67.                         wsprintf( tbuf, "Uploading the file:  %s%s%s\n"
  68.                                   "Using the %s protocol.\n"
  69.                                   "Will %shang up after transfer.",
  70.                                   (LPSTR) path_spec,
  71.                                   *( path_spec + lstrlen( path_spec ) - 1 )
  72.                                   == '\\' ? (LPSTR) "" : (LPSTR) "\\",
  73.                                   (LPSTR) file_name,
  74.                                   (LPSTR) protocols[protocol],
  75.                                   hangup ? (LPSTR) "" : (LPSTR) "not " );
  76.                         MessageBox( NULL, tbuf, "Upload File", MB_OK );
  77.                     }
  78.                     return( TRUE );
  79.  
  80.                 case IDCANCEL:
  81.                     dproc_enter_idcancel( hform );
  82.                     EndDialog( hDlg, TRUE );
  83.                     form_terminate( hform );
  84.                     return( TRUE );
  85.  
  86.                 case BAD_FILENAME:
  87.                     dproc_enter_error( hform );
  88.                     MessageBox( hDlg, "File Not In Directory", NULL, MB_OK );
  89.                     dproc_exit_error( hform, lParam );
  90.                     return( TRUE );
  91.  
  92.                 case ID_FILEBOX:
  93.                     if( HIWORD( lParam ) == LBN_SELCHANGE ) {
  94.                         SendDlgItemMessage( hDlg, ID_FILEBOX, LB_GETTEXT,
  95.                                             (int) SendDlgItemMessage( hDlg,
  96.                                             ID_FILEBOX, LB_GETCURSEL, 0, 0 ),
  97.                                             (LONG) ( (LPSTR) tbuf ) );
  98.                         SetDlgItemText( hDlg, ID_FILENAME, tbuf );
  99.                         return( TRUE );
  100.                     }
  101.                     if( HIWORD( lParam ) == LBN_DBLCLK ) {
  102.                         PostMessage( hDlg, WM_COMMAND, IDOK,
  103.                                      (LONG) GetDlgItem( hDlg, IDOK ) );
  104.                         return( TRUE );
  105.                     }
  106.                     break;
  107.  
  108.                 case ID_DIRBOX:
  109.                     if( HIWORD( lParam ) == LBN_DBLCLK ) {
  110.                         DlgDirSelect( hDlg, path_spec, ID_DIRBOX );
  111.                         SetDlgItemText( hDlg, ID_FILENAME, "" );
  112.                         lstrcat( path_spec, "*.*" );
  113.                         fill_list_boxes( hDlg, path_spec );
  114.                         return( TRUE );
  115.                     }
  116.                     break;
  117.             }
  118.             break;
  119.     }
  120.     return( FALSE );
  121. }
  122.  
  123. /*---------------------------------------------------------------------------*/
  124.  
  125. int FAR PASCAL check_file_name( LPSTR pbuf )
  126. {
  127.     char file_name[13];
  128.  
  129.     lstrcpy( file_name, pbuf );
  130.     str_trim_spaces( file_name );
  131.     return( ( SendDlgItemMessage( GetParent( GetFocus() ), ID_FILEBOX,
  132.             LB_FINDSTRING, -1, (LONG) ( (LPSTR) file_name ) ) == LB_ERR )
  133.             ? 1 : 0 );
  134. }
  135.  
  136. /*---------------------------------------------------------------------------*/
  137.  
  138. static void fill_list_boxes( HWND hDlg, PSTR pathspec )
  139. {
  140.     DlgDirList( hDlg, pathspec, ID_FILEBOX, 0, 0x0001 | 0x0020 );
  141.     DlgDirList( hDlg, pathspec, ID_DIRBOX, ID_PATHSPEC, 0x0010 | 0x4000 |
  142.                 0x8000 );
  143. }
  144.  
  145.